@extends('layouts.admin')

@section('title', '帖子列表')

@section('css')
    <link rel="stylesheet" href="{{cdn('/assets/css/animate.min.css')}}">
@endsection

@section('content')
    <div class="static-content">
        <div class="page-content">
            <ol class="breadcrumb">
                <li class=""><a href="{{url('/admin')}}">Home</a></li>
                <li ><a href="{{url('/admin/topic')}}">Topic</a></li>
                <li class="active"><a href="{{url('/admin/topic/list')}}">List</a></li>
            </ol>
        </div>
        <div class="container-fluid">
            <div data-widget-group="group1" class="ui-sortable">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="panel panel-default" data-widget="{&quot;draggable&quot;: &quot;false&quot;}" data-widget-static="" style="visibility: visible; opacity: 1; display: block; transform: translateY(0px);">
                            <div class="panel-heading">
                                <h2>帖子列表</h2>
                                <div class="panel-ctrls" data-actions-container="" data-action-collapse="{&quot;target&quot;: &quot;.panel-body&quot;}">
                                </div>
                                <div class="options">
                                    <form method="get" action="{{url('/admin/topic/list')}}" style="margin-bottom: 5px">
                                        <div class="form-group pull-right" style="margin-bottom: 0px">
                                            <div class="col-md-12">
                                                <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="fa fa-search"></i>
                                                    </span>
                                                    <input type="text" class="form-control" name="q" placeholder="搜索" value="{{$q or ''}}">
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                            <div class="panel-body">
                                <table class="table m-n">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th>帖子</th>
                                            <th>板块</th>
                                            <th>创建者</th>
                                            <th>最后修改者</th>
                                            <th>创建时间</th>
                                            <th>修改时间</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
@if (!empty($topics))
    @foreach($topics as $topic)
        <tr>
            <td>{{$topic->id or 0}}</td>
            <td><a href="{{url('/forum/topic/'.$topic->id)}}" target="_blank">{{$topic->title or ''}}</a></td>
            <td>{{$topic->partition->title or ''}}</td>
            <td><a href="{{url('/user/info/'.$topic->user->id)}}" target="_blank">{{$topic->user->name or ''}}</a></td>
            <td><a href="{{url('/user/info/')}}/{{$topic->changUser->id or 0}}" target="_blank">{{$topic->changUser->name or ''}}</a></td>
            <td>{{$topic->created_at or ''}}</td>
            <td>{{$topic->updated_at or ''}}</td>
            <td>
                <a href="{{url('/topic/edit/'.$topic->id)}}" class="btn btn-success btn-sm"><i class="fa fa-edit"></i> 编辑</a>
                <a href="#" onclick="deleteThis('{{$topic->id or 0}}', this)" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> 删除</a>
            </td>
        </tr>
    @endforeach
@endif
                                    </tbody>
                                    <tfoot>
                                        <tr>
                                            <td colspan="8">
                                                <div class="pull-right">
                                                    @if (!empty($p))
                                                        {{ $topics->appends(['p' => $p])->links() }}
                                                    @else
                                                        {{ $topics->links() }}
                                                    @endif
                                                </div>
                                            </td>
                                        </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script src="{{cdn('/supervise/assets/plugins/animate/animsition.min.js')}}"></script>
    <script>
        function deleteThis($id, $this) {
            $.post('/admin/topic/del',{
                _token:$('meta[name=csrf-token]').attr('content'),
                id:$id
            },function (date) {
                if (date.code == 0){
                    $tr = $($this).parents('tr');
                    $tr.addClass('bounceOut animated');
                    setTimeout(function () {
                        $($tr).remove();
                    },700);
                }
            })
        }
    </script>
@endsection